<template>
  <div id="screenFull" @click="onToggle">
    <svg-icon
      :icon="isFullscreen? 'exit-fullscreen': 'fullscreen'"
    />
  </div>
</template>

<script setup lang="ts">
import screenFull from 'screenfull'
import { ref, onMounted, onUnmounted } from 'vue'
// 是否全屏
const isFullscreen = ref(false)
// 触发事件
const onToggle = () => {
  screenFull.toggle()
}
// 监听 screenfull 的变化
const change = () => {
  isFullscreen.value = screenFull.isFullscreen
}
// on: 绑定监听
onMounted(() => {
  screenFull.on('change', change)
})
// off: 取消监听
onUnmounted(() => {
  screenFull.on('change', change)
})
</script>
